<style scoped>
  .address-line-height {
    line-height: 32px;
  }
</style>
<template>
  <div>
    <Dialog
      :visible.sync="innerVisible"
      :title="deliveryAddressLength ? '选择提货地址' : '温馨提示'"
    >
      <el-row v-if="deliveryAddressLength">
        <el-radio-group v-model="checkedAddress">
          <el-col :span="22" :offset="2" v-for="(item, index) in deliveryAddress" :key="index">
            <el-radio :label="item">
              <span class="address-line-height">
                {{item.deliveryName}} ({{item.deliveryPhone}}) {{item.deliveryProvince}} {{item.deliveryCity}} {{item.deliveryDistrict}} {{item.deliveryAddress}}
                <span class="font-red" v-if="item.isDefault == '1'">(默认地址)</span>
              </span>
            </el-radio>
          </el-col>
        </el-radio-group>
      </el-row>
      <el-row v-if="!deliveryAddressLength">
        <el-col :span="24" class="text-center">
          <p>你还未添加提货信息，可在【提货地址管理】</p>
          <p>添加常用提货信息，方便选择</p>
        </el-col>
      </el-row>
      <span slot="footer">
        <el-button @click="innerVisible = false">取 消</el-button>
        <el-button type="primary" @click="sure">确 定</el-button>
      </span>
    </Dialog>
  </div>
</template>

<script>
// import {httpGetDetail} from 'assets/scripts/base/util'
export default {
  name: 'choiceAddress',
  components: {},
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      innerVisible: this.visible,
      checkedAddress: {},
      defaultAddress: {},
      deliveryAddress: []
    }
  },
  created() {
  },
  computed: {
    deliveryAddressLength() {
      return this.deliveryAddress.length
    }
  },
  watch: {
    visible(val, oldVal) {
      if (val === oldVal) {
        return
      }
      this.innerVisible = val
      if (val && this.deliveryAddress.length === 0) { // 获取一下
        this.$ajax.get('/ms-warehouse-order/chDefaultPickupInfo/getPickupInfoList').then(response => {
          if (response.success) {
            if (Array.isArray(response.data)) {
              this.deliveryAddress = response.data
            }
          }
        })
      }
    },
    innerVisible(val, oldVal) {
      if (val === oldVal) {
        return
      }
      this.$emit('update:visible', val)
    },
    // 自动选中默认值
    deliveryAddress(val, oldValue) {
      if (Array.isArray(val)) {
        for (let item of val) {
          if (item.isDefault === 1) {
            this.checkedAddress = item
            this.defaultAddress = item
            return
          }
        }
      }
    }
  },
  methods: {
    sure() {
      this.$emit('handleDeliveryAddress', this.checkedAddress)
      this.innerVisible = false
    }
  }
}
</script>
